Skip to content

ethernet: stm32: add a alternative HAL_ETH_Init for V1 api #88483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maass-hamburg
Copy link
Member

add a alternative HAL_ETH_Init for V1 api without phy
configuration, as this is already been done outside of
the ethernet driver.

Signed-off-by: Fin Maaß [email protected]

#if defined(CONFIG_ETH_STM32_HAL_API_V1)
#define ETH_TIMEOUT_SWRESET 500U

HAL_StatusTypeDef HAL_ETH_Init_alt(ETH_HandleTypeDef *heth)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine not using HAL_ETH_Init, but please don't reimplement a HAL function and instead implement as much as possible a zephyr function:
Don't call it HAL_... but use zephyr function name
Don't return HAL type and take dev as argument.
Access ETH registers instead of (heth->Instance)->
....
Likely the 2 only pure HAL things that should remain are the State and Lock updates for further HAL operations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried it

Copy link
Contributor

@clamattia clamattia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note. Why is eth_stm32_init_v1_api happening at driver init. And the equivalent for v2 at api->init (called by net core)?

@maass-hamburg
Copy link
Member Author

Side note. Why is eth_stm32_init_v1_api happening at driver init. And the equivalent for v2 at api->init (called by net core)?

v2 got moved there in #86621. the phy specific code from that than got removed in my #87593. Maybe it can be moved back? @marwaiehm-st what do you think, it was your pr?

@marwaiehm-st
Copy link
Contributor

Side note. Why is eth_stm32_init_v1_api happening at driver init. And the equivalent for v2 at api->init (called by net core)?

v2 got moved there in #86621. the phy specific code from that than got removed in my #87593. Maybe it can be moved back? @marwaiehm-st what do you think, it was your pr?

Yes, I moved the V2 to eth_iface_init in my proposition of autonegotiation because I needed the Ethernet interface to be properly initialized to read the correct value from the register using 'HAL_ETH_ReadPHYRegister'. However, now with #87593 we can moved back to eth_initialize with the V1.

@maass-hamburg maass-hamburg force-pushed the stm32_eth_add_init_v1 branch 2 times, most recently from 6f0eaf8 to 6fe7d22 Compare April 23, 2025 12:26
@maass-hamburg
Copy link
Member Author

Side note. Why is eth_stm32_init_v1_api happening at driver init. And the equivalent for v2 at api->init (called by net core)?

v2 got moved there in #86621. the phy specific code from that than got removed in my #87593. Maybe it can be moved back? @marwaiehm-st what do you think, it was your pr?

Yes, I moved the V2 to eth_iface_init in my proposition of autonegotiation because I needed the Ethernet interface to be properly initialized to read the correct value from the register using 'HAL_ETH_ReadPHYRegister'. However, now with #87593 we can moved back to eth_initialize with the V1.

added a commit to move it back

clamattia
clamattia previously approved these changes Apr 24, 2025
Copy link
Contributor

@clamattia clamattia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for moving the v1 and v2 functions closer together. I have added another small hint. I am not familiar enough with the hal to review the eth_stm32_init_v1_api. From what I can see looks good.

marwaiehm-st
marwaiehm-st previously approved these changes Apr 25, 2025
@maass-hamburg maass-hamburg dismissed stale reviews from marwaiehm-st and clamattia via 3cdcaca May 5, 2025 07:45
@maass-hamburg maass-hamburg force-pushed the stm32_eth_add_init_v1 branch 2 times, most recently from 3cdcaca to 0c4e0e1 Compare May 5, 2025 10:21
@maass-hamburg
Copy link
Member Author

ping @erwango

@maass-hamburg
Copy link
Member Author

@erwango please take a look

@erwango
Copy link
Member

erwango commented Jun 6, 2025

@erwango please take a look

I'll take time next week. Don't hesitate to ping me again.

@maass-hamburg maass-hamburg force-pushed the stm32_eth_add_init_v1 branch from 0c4e0e1 to d83736d Compare June 10, 2025 06:36
@github-actions github-actions bot requested a review from etienne-lms June 10, 2025 06:37
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments

/* Get the ETHERNET MACMIIAR value, this is responsible for mdio, so save it to restore it
* later
*/
tmpreg1 = (heth->Instance)->MACMIIAR;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove the parentheses.
Ditto at lines 880, 883 and 892.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

uint32_t tmpreg1 = 0U;

if (heth->State == HAL_ETH_STATE_RESET) {
/* Allocate lock resource and initialize it */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocate does not really apply here. Maybe simply remove the inline comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 883 to 884
if (WAIT_FOR((((heth->Instance)->DMABMR & ETH_DMABMR_SR) == (uint32_t)RESET),
ETH_TIMEOUT_SWRESET, NULL) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could remove some parentheses (easier to read)

Suggested change
if (WAIT_FOR((((heth->Instance)->DMABMR & ETH_DMABMR_SR) == (uint32_t)RESET),
ETH_TIMEOUT_SWRESET, NULL) == false) {
if (!WAIT_FOR((heth->Instance->DMABMR & ETH_DMABMR_SR) == (uint32_t)RESET,
ETH_TIMEOUT_SWRESET, NULL)) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return -ETIMEDOUT;
}

(heth->Instance)->MACMIIAR = (uint32_t)tmpreg1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast not needed, tmpreg1 is already of type uint32_t.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@maass-hamburg maass-hamburg force-pushed the stm32_eth_add_init_v1 branch from d83736d to 0cc6663 Compare June 10, 2025 09:38
Copy link

@maass-hamburg
Copy link
Member Author

@erwango please take a look

I'll take time next week. Don't hesitate to ping me again.

ping @erwango

@maass-hamburg
Copy link
Member Author

@erwango ping

@erwango
Copy link
Member

erwango commented Jul 25, 2025

@marwaiehm-st Could you have a cross check and perform non regression on the changes ?

heth->Instance->MACMIIAR = tmpreg1;

/* Config MAC and DMA */
ETH_MACDMAConfig(heth, ETH_SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function ETH_MACDMAConfig is defined as static in the STM32 HAL module.

static void ETH_MACDMAConfig(ETH_HandleTypeDef *heth, uint32_t err);

Using ETH_MACDMAConfig here will cause a build error (undefined reference) because it is not accessible from other modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as changing the hal is now necessary, it was easier, to just remove the phy init and config code from the v1 HAL_ETH_Init

the phy is already configured by the phy driver in zephyr
and we don't want to overwrite it in the HAL_ETH_Init
function in the stm32 HAL.

Signed-off-by: Fin Maaß <[email protected]>
@maass-hamburg maass-hamburg force-pushed the stm32_eth_add_init_v1 branch from 0cc6663 to b0d7838 Compare August 1, 2025 09:04
Copy link

github-actions bot commented Aug 1, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_stm32 zephyrproject-rtos/hal_stm32@1e75326 zephyrproject-rtos/hal_stm32#300 zephyrproject-rtos/hal_stm32#300/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-hal_stm32 DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Aug 1, 2025
@maass-hamburg maass-hamburg force-pushed the stm32_eth_add_init_v1 branch from b0d7838 to 6df0e3f Compare August 1, 2025 09:17
Copy link

sonarqubecloud bot commented Aug 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Ethernet DNM (manifest) This PR should not be merged (controlled by action-manifest) manifest manifest-hal_stm32 platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants